﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Lamex.Library;

namespace Lamex.mMES.UI
{
    public partial class frmMES_Lab_TreeList : frmBaseChild
    {
        public frmMES_Lab_TreeList()
        {
            InitializeComponent();
            //Dev 控件treelist等滚动条使用
            //https://blog.csdn.net/vbloveshllm/article/details/23820115

            //DevExpress WinForms v19.1新版亮点：Tree List等控件性能增强
            //https://blog.csdn.net/AABBbaby/article/details/93862961?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

        }

        private void frmMES_Lab_TreeList_Load(object sender, EventArgs e)
        {
            string strSql = @"SELECT KeyIndex,ParentIndex,Item_No AS 编号,Item_Caption AS 主题,Item_Desc AS 内容,Leader AS 负责,Member AS 协助,
						Finish_Percentage AS 完成比例,Start_Date AS 开始日期,Due_Date AS 预计完成,
						Finish_Date AS 实际完成,Project_Type AS 项目类型
                        FROM [LamexMESManager].[dbo].[View_PJT_Project_Progress_Union] 
						WHERE Finish_Date IS NULL";

            DataTable dt = Lamex.Base.BaseBuildSql.GetDataTableBySql(strSql);
            
            //TreeList绑定数据
            treeList1.DataSource = dt;

            treeList1.KeyFieldName = "KeyIndex";
            treeList1.ParentFieldName = "ParentIndex";
            treeList1.EndUpdate();
            treeList1.ExpandAll();
            treeList1.Columns[0].Width = 180;
            //treeList1.Columns[0].BestFit();
        }

        private void frmMES_Lab_TreeList_Resize(object sender, EventArgs e)
        {
            splitContainerControl1.Panel1.Width = this.Width * 4 / 5;
        }

        private void setTreeListProperty()
        {

            //treeList1.OptionsView.AutoWidth = false; //禁用自动宽度

            //treeList1.Columns["stateName"].Width = 180; //设置指定列宽

            //treeList1.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;

            //默认显示下拉三角形样式，设置TreeList的两个皮肤属性即可变成连接虚线

            treeList1.LookAndFeel.UseDefaultLookAndFeel = false;

            treeList1.LookAndFeel.UseWindowsXPTheme = true;



            treeList1.OptionsView.ShowHorzLines = false; //是否显示水平线。默认为True；

            treeList1.OptionsView.ShowVertLines = true; //是否显示垂直线。默认为True；

            treeList1.OptionsView.ShowIndicator = false; //是否显示Node的指示符面板，就是最左边有个三角箭头。默认为True；

            treeList1.OptionsView.ShowButtons = true; //是否显示展开与收缩按钮。默认为True；

            treeList1.OptionsView.ShowColumns = false; //是否显示列标题。默认为True；

            treeList1.OptionsView.ShowIndentAsRowStyle = false; //是否用相应Node的Appearance设置来生成Tree的缩进（没看懂）。默认为False

            treeList1.OptionsView.FocusRectStyle = DevExpress.XtraTreeList.DrawFocusRectStyle.None; //在获得焦点的Cell上，是否显示焦点框架。默认为True；

            //treeList1.OptionsView.FocusRectStyle = DrawFocusRectStyle.CellFocus;

            treeList1.OptionsView.ShowRoot = true; //是否在根Node间显示连接线。默认为True；

            treeList1.OptionsView.ShowCheckBoxes = false; //显示勾选框。默认为False

            //treeList1.OptionsDragAndDrop.DragNodesMode = DragNodesMode.None;//拖拽节点

            treeList1.OptionsBehavior.ReadOnly = true; //只读

            treeList1.OptionsBehavior.Editable = false; //不可编辑

            treeList1.OptionsBehavior.AllowIndeterminateCheckState = true; //设置节点是否有中间状态，即一部分子节点选中，一部分子节点没有选中

            treeList1.OptionsSelection.InvertSelection = true; //选中风格是只应用于选中的Cell

            treeList1.OptionsSelection.MultiSelect = false; //允许多选

            treeList1.OptionsSelection.EnableAppearanceFocusedCell = true; //选中的Cell的Appearance设置是否可用

            treeList1.ExpandAll(); //展开所有层级

            // treeList1.ExpandToLevel(0); //展开的层级



            ////注册这两个事件实现选择父节点自动选子节点，反之亦然

            //treeList1.BeforeCheckNode += treeList1_BeforeCheckNode;

            //treeList1.AfterCheckNode += treeList1_AfterCheckNode;



            //treeList1.AfterFocusNode += treeList1_AfterFocusNode;

            //treeList1.DoubleClick += treeList1_DoubleClick; //但要注意的是要在TreeList.OptionsBehavior.Editable = false的情况下，双击Node才能触发该事件

            ////设置图片

            //// treeList1.CustomDrawNodeImages += treeList1_CustomDrawNodeImages;

            //// 颜色设置

            ////treeList1.Appearance.Row.BackColor = Color.Transparent;//节点默认背景色

            ////  treeList1.Appearance.FocusedRow.BackColor = Color.Orange; // 选中节点的背景色

            ////  treeList1.Appearance.HideSelectionRow.BackColor = Color.LightYellow;//选中节点失去焦点时的背景色

        }

    }
}